﻿// ./about/About.cpp : 实现文件
//
#include "stdafx.h"
#include "LogMasterUi.h"
#include <ossDir.h>
#include <ossDll.h>
#include <ossString.h>
#include "LabelDeviceBase.hpp"

// About

IMPLEMENT_DYNAMIC(LogMasterUi, LabelUiBase)
#define LOG_MSG   (LD_MSG_MAX + 1)

LogMasterUi::LogMasterUi(LabelUiBase* pParentDdfwUi, OssJson& createInfo)
    :LabelUiBase(pParentDdfwUi, createInfo)
	,m_iRowNum(0)
{
  
}

LogMasterUi::~LogMasterUi()
{
}


BEGIN_MESSAGE_MAP(LogMasterUi, LabelUiBase)
    ON_WM_CREATE()
	ON_BN_CLICKED(LOG_MSG,&LogMasterUi::OnUpdateLogMsg)
	ON_MESSAGE(LOG_MSG,&LogMasterUi::OnLogMsg)
END_MESSAGE_MAP()



// About 消息处理程序
int LogMasterUi::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (LabelUiBase::OnCreate(lpCreateStruct) == -1)
        return -1;

	m_font.CreatePointFont(135, _T("微软雅黑"));

	m_logList.Create(WS_CHILD|WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL ,CRect(0,0,0,0),this,0xffff);
	m_logList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	m_logList.SetFont(&m_font);

	const char* items[]={"日志内容",NULL};

	for(int i=0;items[i];i++)
	{
		m_logList.InsertColumn(i,(LPCTSTR)items[i]);
	}

	m_updateLogInfo.Create(_T("刷新"), WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, CRect(0, 0, 0,0), this, LOG_MSG);
    return 0;
}

void LogMasterUi::SizeChange(UINT nType, int cx, int cy)
{
	m_updateLogInfo.MoveWindow(cx - 100, 0, 100, 30);

	m_logList.MoveWindow(0,30,cx,cy-30);
	m_logList.SetColumnWidth(0,cx);
}

void LogMasterUi::OnUpdateLogMsg()
{
	OssJson request;

	request["msgId"] = "getLogMsg";
	request["msg"]["size"] = 1500;

	SendRequest(request, LOG_MSG);
}

LRESULT LogMasterUi::OnLogMsg(WPARAM wParam,LPARAM lParam)
{
	OssJson& response = *(OssJson*)wParam;
	OssJson& result = response["result"];

	if (strcmp(result.asCString(),"success") != 0)
	{
		MessageBox(result.asCString());
		return NULL;
	}

	OssJson& logInfos = response["msg"]["logInfos"];

	m_logList.DeleteAllItems();
	for (size_t i = 0; i < logInfos.Size(); i++)
	{
		OssJson& logInfo = logInfos[i];

		m_logList.InsertItem(m_logList.GetItemCount(), logInfo.asCString());
	}

	return NULL;
}

static OssVersion g_version={
	"V3.0.0.0",
	"logMaster",
	"吴建凰",
	__DATE__,
	"创建logMaster驱动界面 吴建凰 2021年10月3日\n"   //不能加逗号，多次信息一次增加
	"将logMaster升级到3.0.0.0版本。wjh 2022年6月10日\n"
	"\n\n"
};

LABEL_UI_ENTRY(LogMasterUi)


